package net.realsee.controller.wcs.warehouse;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import net.realsee.common.annotation.Log;
import net.realsee.common.annotation.RepeatSubmit;
import net.realsee.common.enums.BusinessType;
import net.realsee.common.utils.poi.ExcelUtil;
import net.realsee.domain.wcs.warehouse.bo.WcsWarehouseLocStatusBo;
import net.realsee.domain.wcs.warehouse.vo.WcsWarehouseLocStatusVo;
import net.realsee.framework.core.controller.BaseController;
import net.realsee.framework.core.domain.PageQuery;
import net.realsee.framework.core.domain.R;
import net.realsee.framework.core.page.TableDataInfo;
import net.realsee.framework.core.validate.AddGroup;
import net.realsee.framework.core.validate.EditGroup;
import net.realsee.service.wcs.warehouse.IWcsWarehouseLocStatusService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 库位状态
 *
 * @author realsee
 * @date 2023-08-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wcs/warehouseLocStatus")
public class WcsWarehouseLocStatusController extends BaseController {

    private final IWcsWarehouseLocStatusService iWcsWarehouseLocStatusService;

    /**
     * 查询库位状态列表
     */
    @SaCheckPermission("wcs:warehouseLocStatus:list")
    @GetMapping("/list")
    public TableDataInfo<WcsWarehouseLocStatusVo> list(WcsWarehouseLocStatusBo bo, PageQuery pageQuery) {
        return iWcsWarehouseLocStatusService.selectVoPage(bo, pageQuery);
    }

    /**
     * 导出库位状态列表
     */
    @SaCheckPermission("wcs:warehouseLocStatus:export")
    @Log(title = "库位状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(WcsWarehouseLocStatusBo bo, HttpServletResponse response) {
        List<WcsWarehouseLocStatusVo> list = iWcsWarehouseLocStatusService.selectVoList(bo);
        ExcelUtil.exportExcel(list, "库位状态", WcsWarehouseLocStatusVo.class, response);
    }

    /**
     * 获取库位状态详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("wcs:warehouseLocStatus:query")
    @GetMapping("/{id}")
    public R<WcsWarehouseLocStatusVo> getInfo(@NotNull(message = "主键不能为空")
                                              @PathVariable Long id) {
        return R.ok(iWcsWarehouseLocStatusService.selectVoById(id));
    }

    /**
     * 新增库位状态
     */
    @SaCheckPermission("wcs:warehouseLocStatus:add")
    @Log(title = "库位状态", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WcsWarehouseLocStatusBo bo) {
        return toAjax(iWcsWarehouseLocStatusService.insertByBo(bo));
    }

    /**
     * 修改库位状态
     */
    @SaCheckPermission("wcs:warehouseLocStatus:edit")
    @Log(title = "库位状态", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WcsWarehouseLocStatusBo bo) {
        return toAjax(iWcsWarehouseLocStatusService.updateByBo(bo));
    }

    /**
     * 删除库位状态
     *
     * @param ids 主键串
     */
    @SaCheckPermission("wcs:warehouseLocStatus:remove")
    @Log(title = "库位状态", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iWcsWarehouseLocStatusService.deleteWithValidByIds(Arrays.asList(ids)));
    }
}
